<!DOCTYPE html>
<html>
<!--
Copyright 2012 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.crypt.sha256</title>
<script src="../base.js"></script>
<script>
  goog.require('goog.crypt');
  goog.require('goog.crypt.hashTester');
  goog.require('goog.crypt.Sha256');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>

function testBasicOperations() {
  var sha256 = new goog.crypt.Sha256();
  goog.crypt.hashTester.runBasicTests(sha256);
}

function testHashing() {
  // Test vectors from:
  // csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf

  var sha256 = new goog.crypt.Sha256();

  // Empty message.
  sha256.update([]);
  assertElementsEquals(
      goog.crypt.hexToByteArray(
          'e3b0c44298fc1c149afbf4c8996fb924' +
          '27ae41e4649b934ca495991b7852b855'),
      sha256.digest());

  // One block message.
  sha256.reset();
  sha256.update(goog.crypt.stringToByteArray('abc'));
  assertElementsEquals(
      goog.crypt.hexToByteArray(
          'ba7816bf8f01cfea414140de5dae2223' +
          'b00361a396177a9cb410ff61f20015ad'),
      sha256.digest());

  // Multi-block message.
  sha256.reset();
  sha256.update(
      goog.crypt.stringToByteArray(
          'abcdbcdecdefdefgefghfghighij' +
          'hijkijkljklmklmnlmnomnopnopq'));
  assertElementsEquals(
      goog.crypt.hexToByteArray(
          '248d6a61d20638b8e5c026930c3e6039' +
          'a33ce45964ff2167f6ecedd419db06c1'),
      sha256.digest());
}

</script>
</body>
</html>
